package com.atguigu.servlet;

import com.atguigu.listener.MyActivationListener;
import com.atguigu.listener.SessionBindingListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/servlet1")
public class Servlet1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //向应用域中放入数据
        ServletContext servletContext = this.getServletContext();
        servletContext.setAttribute("keya", "valuea");

        //session
                //绑定
        HttpSession session = req.getSession();
        //绑定监听器
        SessionBindingListener sbl = new SessionBindingListener();
        //绑定
        session.setAttribute("sbl", sbl);

        //活化
        MyActivationListener myActivationListener = new MyActivationListener();
        session.setAttribute("lis", myActivationListener);


        session.setAttribute("s_keyb", "valueb");

        //手动销毁session
        session.invalidate();

        //request
    }
}
